package com.ntschy.web.controller.bt;


import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ntschy.bt.entity.dataobject.BtHelp.BtHelp;
import com.ntschy.bt.entity.dto.BtHelpDTO.InputDTO.BtHelpInputDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.InputDTO.BtHelpInputPageDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.overviewDTO.BtHelpOveriewAmendDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.overviewDTO.BtHelpOverviewDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.overviewDTO.BtHelpOverviewPageDTO;
import com.ntschy.bt.entity.enums.BtHelpStatusEnum;
import com.ntschy.bt.entity.mapstruct.BtHelpInputMapstruct;
import com.ntschy.bt.entity.mapstruct.BtHelpOverviewMapstruct;
import com.ntschy.bt.entity.valid.BtSupplyShopGroups;
import com.ntschy.bt.entity.vo.BtHelp.Input.BtHelpInputPageVO;
import com.ntschy.bt.entity.vo.BtHelp.Overview.BtHelpOverviewPageVO;
import com.ntschy.bt.service.IBtHelp.IBtHelpInputService;
import com.ntschy.bt.service.IBtHelp.IBtHelpOverviewService;
import com.ntschy.common.core.AjaxPageResult;
import com.ntschy.common.core.AjaxResult;
import com.ntschy.common.core.controller.BaseController;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author
 * @since
 */

@Validated
@RestController
@RequestMapping("/bt/help")
public class BtHelpOverviewController extends BaseController {

    @Resource
    private IBtHelpOverviewService btHelpOverviewService;

    @Resource
    private IBtHelpInputService btHelpInputService;

    // * ================================================基础增删改查BEGIN============================================= *
    /**
     * 求助列表分页列表
     *
     * @param btHelpInputPageDTO
     * @return
     */
    @ApiOperation(value = "求助列表分页列表", notes = "")
    @ApiImplicitParam(name = "pageWaitEntryHelp", value = "求助列表分页查询", required = true, dataType = "BtHelpReviewPageDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/pageOverviewHelp")
    public AjaxPageResult<BtHelpOverviewPageVO> pageOverviewHelp(@Validated @RequestBody BtHelpOverviewPageDTO btHelpInputPageDTO) {
        Page<BtHelp> page = PageHelper.startPage(btHelpInputPageDTO.getCurrPage(), btHelpInputPageDTO.getPageSize());
        BtHelp btHelp = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.pagetableDto(btHelpInputPageDTO);
        List<BtHelp> btHelps = btHelpOverviewService.pageHelpInput(btHelp);
        List<BtHelpOverviewPageVO> btHelpOverviewPageVOS = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.pagePustrespone(btHelps);
        return buildPageResult(btHelpOverviewPageVOS,page);

    }


    /**
     *保存求助
     *
     * @param btHelpOverviewDTO
     * @return
     */
    @ApiOperation(value = "保存求助", notes = "")
    @ApiImplicitParam(name = "addSaveHelp", value = "保存求助", required = true, dataType = "btHelpOverviewDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/addSaveHelp")
    public AjaxResult<String> addSaveHelp(@Validated @RequestBody BtHelpOverviewDTO btHelpOverviewDTO){
        BtHelp btHelp = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.overview_CHANGE_bthelp(btHelpOverviewDTO);
        btHelp.setStatus(BtHelpStatusEnum.TO_SUBMIT);
        btHelp.setId(IdUtil.fastUUID());
        int i = btHelpOverviewService.insertOverview(btHelp);

        return  toAjax(i,"保存成功","保存失败");
    }


    /**
     *提交求助
     *
     * @param btHelpOverviewDTO
     * @return
     */
    @ApiOperation(value = "保存求助", notes = "")
    @ApiImplicitParam(name = "addSaveHelp", value = "保存求助", required = true, dataType = "btHelpOverviewDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/addSubmitHelp")
    public AjaxResult<String> addSubmitHelp(@Validated @RequestBody BtHelpOverviewDTO btHelpOverviewDTO){
        BtHelp btHelp = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.overview_CHANGE_bthelp(btHelpOverviewDTO);
        btHelp.setStatus(BtHelpStatusEnum.TO_BE_ASSIGNED);
        btHelp.setId(IdUtil.fastUUID());
        int i = btHelpOverviewService.insertOverview(btHelp);

        return  toAjax(i,"提交成功","提交失败");
    }


    /**
     *修改求助
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改求助", notes = "")
    @ApiImplicitParam(name = "addSaveHelp", value = "修改求助", required = true, dataType = "btHelpOverviewDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/updateHelp")
    public AjaxResult<String> updateHelp(@Validated @RequestBody BtHelpOveriewAmendDTO btHelpOveriewAmendDTO){
        BtHelp btHelp = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.OveriewAmend_CHANGE_bthelp(btHelpOveriewAmendDTO);
        int i = btHelpOverviewService.updateOverview(btHelp);
        return  toAjax(i,"提交成功","提交失败");
    }

    /**
     *修改求助
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改求助", notes = "")
    @ApiImplicitParam(name = "addSaveHelp", value = "修改求助", required = true, dataType = "btHelpOverviewDTO")
    //@PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/modifyOverview")
    public AjaxResult<String> modifyOverview(@Validated @RequestBody BtHelpOveriewAmendDTO btHelpOveriewAmendDTO){
        BtHelp btHelp = BtHelpOverviewMapstruct.BT_HELP_ASSIGN_MAP_STRUCT.OveriewAmend_CHANGE_bthelp(btHelpOveriewAmendDTO);
        btHelp.setStatus(BtHelpStatusEnum.TO_BE_ASSIGNED);
        int i = btHelpOverviewService.modifyOverview(btHelp);
        return  toAjax(i,"提交成功","提交失败");
    }


    /*deleteHelp*/

    /**
     *删除求助
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改求助", notes = "")
    @ApiImplicitParam(name = "addSaveHelp", value = "修改求助", required = true, dataType = "btHelpOverviewDTO")
    @PreAuthorize("@ss.hasPermi('bt:supplyshop:page')")
    @PostMapping("/deleteHelp")
    public AjaxResult<String> deleteHelp(@Validated @RequestBody String id){
        BtHelp btHelp = btHelpInputService.detailsHelpInput(id);
        int i = 0;
        if(btHelp.getStatus()==BtHelpStatusEnum.TO_SUBMIT){
             i = btHelpOverviewService.deleteHelp(id);
        }
        return  toAjax(i,"删除成功","删除失败");
    }




    // * ================================================基础增删改查BEGIN============================================= *


}
